package io.renren.modules.backstage.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.backstage.entity.InfoEntity;
import io.renren.modules.backstage.service.InfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 消息中心表
 *
 * @author syh
 * @email sunlightcs@gmail.com
 * @date 2022-05-19 09:40:52
 */
@RestController
@RequestMapping("backstage/info")
public class InfoController {
    @Autowired
    private InfoService infoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("crud:info:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = infoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{infoId}")
    @RequiresPermissions("crud:info:info")
    public R info(@PathVariable("infoId") Integer infoId){
		InfoEntity info = infoService.getById(infoId);

        return R.ok().put("info", info);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("crud:info:save")
    public R save(@RequestBody InfoEntity info){
		infoService.save(info);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("crud:info:update")
    public R update(@RequestBody InfoEntity info){
		infoService.updateById(info);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("crud:info:delete")
    public R delete(@RequestBody Integer[] infoIds){
		infoService.removeByIds(Arrays.asList(infoIds));

        return R.ok();
    }

    /**
     * 发送中奖消息
     * @param userId
     * @param text
     */
    @RequestMapping("sendInfo")
    public void sendInfo(@RequestParam("userId") Integer userId,@RequestParam("text") String text){
        infoService.sendInfo(userId,text);
    }

}
